package cn.org.itool.ws.framework.event;

import cn.org.itool.ws.framework.netty.auth.Principal;

import java.util.Collections;
import java.util.Map;
import java.util.StringJoiner;

/**
 * 开启WS链接事件
 *
 */
public class OpenEvent extends WsEvent {

    /**
     * WS编号
     */
    private final String wsId;

    /**
     * 客户端ip地址
     */
    private final String ip;

    /**
     * 链接参数
     */
    private final Map<String, String> params;

    /**
     * 构造{@link OpenEvent}
     *
     * @param principal {@link Principal}
     * @param wsId WS编号
     * @param ip 客户端ip地址
     */
    public OpenEvent(Principal principal, String wsId, String ip, Map<String, String> params) {
        super(principal);
        this.wsId = wsId;
        this.ip = ip;
        this.params = params;
    }

    /**
     * 构造{@link OpenEvent}
     *
     * @param principal {@link Principal}
     * @param wsId WS编号
     * @param ip 客户端ip地址
     */
    public OpenEvent(Principal principal, String wsId, String ip) {
        this(principal, wsId, ip, Collections.emptyMap());
    }

    /**
     * 构造{@link OpenEvent}
     *
     * @param principal {@link Principal}
     * @param wsId WS编号
     */
    public OpenEvent(Principal principal, String wsId){
        this(principal, wsId, "0.0.0.0");
    }

    public String getWsId() {
        return wsId;
    }

    public String getIp() {
        return ip;
    }

    public Map<String, String> getParams() {
        return params;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", OpenEvent.class.getSimpleName() + "[", "]")
                .add("wsId='" + wsId + "'")
                .add("ip='" + ip + "'")
                .add("params=" + params)
                .toString();
    }
}
